// componentlibrary.h
#ifndef COMPONENTLIBRARY_H
#define COMPONENTLIBRARY_H

#include <QWidget>
#include <QTreeWidget>
#include <QListWidget>
#include <QStackedWidget>
#include <QMouseEvent>
#include "component.h"

class ComponentLibrary : public QWidget
{
    Q_OBJECT

public:
    explicit ComponentLibrary(QWidget *parent = nullptr);
    void clearSelection();
    Component* getComponentByName(const QString &name);

signals:
    void componentSelectedForPlacement(Component *component);
    void componentDoubleClicked(Component *component);

private:
    void setupCategories();
    void addCategory(const QString &name, const QList<Component*> &components);
    void startDrag(Qt::DropActions supportedActions);

    QTreeWidget *categoriesTree;
    QListWidget *componentsList;
    QStackedWidget *stackedWidget;
    QMap<QString, QList<Component*>> componentMap;

protected:
    void mouseDoubleClickEvent(QMouseEvent *event) override;
};

#endif // COMPONENTLIBRARY_H
